#include <linux/interrupt.h>
#include<linux/irq.h>
#include <linux/module.h>

MODULE_LICENSE("GPL");

static int irq = 12;        //中断号定义


// 自定义中断处理函数
static irqreturn_t irq_handler(int data, void *dev_id)
{
	printk("the data is :%d\n", data);    //data是对应中断的中断号
	printk("in the interrupt handler function\n");
	return IRQ_WAKE_THREAD;               //触发中断线程函数执行
}

// 自定义中断线程处理函数
static irqreturn_t irq_thread_fn(int data, void *dev_id)
{
	printk("the data is :%d\n", data);  //data是对应中断的中断号
	printk("in the interrupt thread function\n");
	return IRQ_HANDLED;
}

static int __init request_threaded_irq_init(void)
{
	int result=0;
	printk("into request_threaded_irq_init\n");
	/* 调用request_threaded_irq( )函数irq是对应的中断编号irq_handler是定义的中断
	处理函数irq_thread_fn是对应的中断线程处理函数IRQF_DISABLED是中断的类型*/
//	result=request_threaded_irq(irq, irq_handler, irq_thread_fn, IRQF_DISABLED, "A_New_Device", NULL);
	result=request_threaded_irq(irq, irq_handler, irq_thread_fn, 0x00000020, "A_New_Device", NULL);
	printk("the result of the request_threaded_irq is: %d\n", result);
	// 显示函数调用结果
	disable_irq(irq);     //中断不可用
	enable_irq(irq);      //使能中断触发中断处理函数的执行
	printk("out request_threaded_irq_init\n");
	return 0;
}


static void __exit request_threaded_irq_exit(void)
{
	free_irq(irq, NULL);   //释放申请的中断
	printk("Goodbye request_threaded_irq\n");
	return;
}

module_init(request_threaded_irq_init);
module_exit(request_threaded_irq_exit);
